<?php
/**
 * 网站内容管理
 *
 * User: Youzi
 */
class SitemanageController extends Controller
{

    /**
     * 网站公告
     */
    public function BulletinAction()
    {
        $this->data['bulletin_list'] = BulletinModel::getInstance()->getList();

        $this->view("site_manage/bulletin.list");
    }

    public function BulletinaddAction()
    {
        if (P('title') && P('content')) {
            $data = array(
                'title' => P('title'),
                'content' => P('content'),
                'created' => time(),
            );
            if (BulletinModel::getInstance()->add($data)) {
                redirect('/sitemanage/bulletin/');
            }
        }
        $this->data['bulletin_list'] = BulletinModel::getInstance()->getList();
        $this->view("site_manage/bulletin.add");
    }

    public function BulletineditAction()
    {
        $id = G('id');
        if (P('title') && P('content')) {
            $data = array(
                'title' => P('title'),
                'content' => P('content'),
            );
            if (BulletinModel::getInstance()->edit($data, $id)) {
                redirect('/sitemanage/bulletin/');
            }
        }
        $detail = BulletinModel::getInstance()->getInfo($id);
        $this->data['detail'] = $detail;
        $this->view('site_manage/bulletin.edit');
    }

    public function BulletindelAction()
    {
        // 取得数据
        $id = trim(P('id',0));

        // 写数据库
        BulletinModel::getInstance()->del($id);

        // 判断数据库插入是否正常
        $this->json->code('OK')->out();
        return false;
    }

    /**
     * 广告位管理
     */
    public function AdAction()
    {
        $list = AdModel::getInstance()->getList();
        $this->data['list'] = $list;
        $this->view("site_manage/ad.list");
    }

    /**
     * 添加广告位
     */
    public function AdaddAction()
    {

        if (P('links')) {
            $result = UploadTool::doImages('img');
            $sorts = P('sorts') ? (int)P('sorts') : 255;
            $data = array(
                'img'       => $result['url'],
                'links'     => P('links'),
                'sorts'     => $sorts,
                'created'   => time()
            );
            if (AdModel::getInstance()->add($data)) {
                redirect('/sitemanage/ad/');
            }
        }
        $this->view('site_manage/ad.add');
    }

    /**
     * 修改广告位
     */
    public function AdeditAction()
    {
        $id = G('id');
        if (P('links') && $id) {
            if ($_FILES['img']['tmp_name']) {
                $result = UploadTool::doImages('img');
                $img = $result['url'];
            } else {
                $img = P('old_img');
            }

            $sorts = P('sorts') ? (int)P('sorts') : 255;
            $data = array(
                'img'       => $img,
                'links'     => P('links'),
                'sorts'     => $sorts,
            );
            if (AdModel::getInstance()->edit($data, $id)) {
                redirect('/sitemanage/ad/');
            }
        }
        $detail = AdModel::getInstance()->getInfo($id);
        $this->data['detail'] = $detail;
        $this->view('site_manage/ad.edit');
    }

    /**
     * 删除广告位
     */
    public function AddelAction()
    {
        // 取得数据
        $id = trim(P('id',0));

        // 写数据库
        AdModel::getInstance()->del($id);

        // 判断数据库插入是否正常
        $this->json->code('OK')->out();
        return false;
    }

    /**
     * 业务咨询
     *
     * 软件业务 硬件业务 网吧装修业务
     */
    public function BusinessAction()
    {
        $list = AdvisoryIntroductionModel::getInstance()->getList();
        $this->data['list'] = $list;
        $this->view('site_manage/advisory.introduction.list');
    }

    public function BusinessEditAction()
    {
        $id = G('id');
        if (P('content') && $id) {
            $data = array(
                'content' => P('content'),
            );
            if (AdvisoryIntroductionModel::getInstance()->edit($data, $id)) {
                redirect('/sitemanage/Business/');
            }
        }
        $detail = AdvisoryIntroductionModel::getInstance()->getInfo($id);
        $this->data['detail'] = $detail;
        $this->view('site_manage/advisory.introduction.edit');
    }

    /**
     * 区域管理
     * Enter description here ...
     */
    function AreaAction(){
		$this->view("basic.area","item");
    }
}
